package com.txby.platformApi.component.web;

import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.jck.mybatis.log.GlobalLogAnnotation;
import com.jck.mybatis.util.PageBean;
import com.jck.mybatis.util.PageList;
import com.jck.tools.ChkUtil;
import com.txby.platformCore.component.service.CommonController;
import com.txby.platformCore.data.CommonApiModelMapExt;
import com.txby.platformCore.entity.ProductDeviceInit;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 消息
* @author duke
* @date  2017年9月23日09:21:22
 */
@SuppressWarnings("all")
@RestController
@Api(value="护士站消息",description="护士-说明")
@RequestMapping("/nurse")
public class NurseController extends CommonController{
	private static Logger log = Logger.getLogger(NurseController.class);

	@ApiOperation(value = "根据设备sn号获取病区", notes = "根据设备sn号获取病区")
	@GetMapping("/getQuerySickArea/{type}/{token}")
	@GlobalLogAnnotation(logType=2,discription="根据设备sn号获取病区")
	public Map getQuerySickArea(@PathVariable("type") Integer type, @PathVariable("token") String token,@RequestParam(name="deviceSN",required=true) String deviceSN) {
		CommonApiModelMapExt mm = chekTokenCahceValid(token, type);
		ProductDeviceInit pd=null;
		try {
			if (!isTokenValid ||ChkUtil.isEmpty(deviceSN)) {
				return mm;
			}
			Map paramMap = new HashMap<>();
			
			String searchSql = "SELECT name,t2.sickAreaNO FROM sys_dept,t_txby_productDeviceInit t2 WHERE parent_id = ( SELECT deptId FROM t_txby_productDeviceInit WHERE 1 = 1 AND deviceSN = #{pojo.deviceSN} ) AND type = 2 and deviceSN =#{pojo.deviceSN}";
			paramMap.put("deviceSN",  deviceSN);
			PageList pl=new PageList<ProductDeviceInit>();
			PageBean pb = new PageBean();
			pl = this.mBaseDao.findBySqlForPageList(searchSql, Map.class, pb, paramMap);
			mm.put(CommonApiModelMapExt.ERRCODE, 0);
			mm.put(CommonApiModelMapExt.ERRMSG, "查询成功");
			mm.put("data",pl.getResultList());
			return mm;
		} catch (Exception e) {
			e.printStackTrace();
			mm.put(CommonApiModelMapExt.ERRCODE, 1);
			mm.put(CommonApiModelMapExt.ERRMSG, "系统异常");
			mm.put("data",pd);
		}
		return mm;
	}
	
}